package com.star.links;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.Toast;

import com.star.links.Service.ISettingFragmentCallBack;
import com.star.links.configure.PlayConfigure;


public class SettingFragment extends Fragment implements View.OnClickListener, PopupMenu.OnMenuItemClickListener {


    private View rootView;
    private EditText menu;

    private ISettingFragmentCallBack iSettingFragmentCallBack;
    public void setISettingFragmentCallBack(ISettingFragmentCallBack callBack){
        iSettingFragmentCallBack=callBack;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if(rootView==null) {
            rootView= inflater.inflate(R.layout.fragment_setting, container, false);
        }
        menu=rootView.findViewById(R.id.difficultyLevel);
        menu.setOnClickListener(this);
        return rootView;
    }

    @Override
    public void onClick(View view) {
        PopupMenu popupMenu=new PopupMenu(getActivity(),view);
        popupMenu.inflate(R.menu.difficulty_menu);
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.show();
    }

    @Override
    public boolean onMenuItemClick(MenuItem menuItem) {
        switch (menuItem.getItemId()){
            case R.id.simple:
                menu.setText("简单");
                iSettingFragmentCallBack.sendMsgToActivity(0);
                break;
            case R.id.medium:
                menu.setText("中等");
                iSettingFragmentCallBack.sendMsgToActivity(1);
                break;
            case R.id.difficulty:
                menu.setText("困难");
                iSettingFragmentCallBack.sendMsgToActivity(2);

                break;
            default:
                break;
        }
        Toast.makeText(SettingFragment.this.getContext(),"设置成功",Toast.LENGTH_SHORT).show();
        return false;
    }
}